package com.deyuanyun.pic.risk.controller.vo;


import com.deyuanyun.pic.common.util.StringUtils;
import com.deyuanyun.pic.common.util.format.DateFormat;
import com.deyuanyun.pic.common.util.format.NumberFormat;
import com.deyuanyun.pic.pipe.controller.vo.BaseVOUtil;
import com.deyuanyun.pic.risk.domain.RiskAssessment;
import com.deyuanyun.pic.settings.support.biz.CodeUtil;
import com.deyuanyun.pic.settings.support.biz.PipeLineUtil;
import com.github.pagehelper.Page;

import java.util.*;

/**
 * 风险评价返回对象
 *
 * @author huanglw
 * @date 2016-7-28
 *
 * History: [修改人][时间][修改描述]
 */
public class RiskAssessmentVO {

    /**
     * 主键
     */
    private String id;

    /**
     * 创建备注
     */
    private String remark;

    /**
     * 管道ID
     */
    private String pipeLineName;

    /**
     * 统一编号
     */
    private String code;

    /**
     * 风险段编号(自定义编号)
     */
    private String customNumber;

    /**
     * 风险段名称
     */
    private String name;

    /**
     * 风险管段长度（m）
     */
    private String length;

    /**
     * 起点位置描述
     */
    private String fromLocationDescription;

    /**
     * 终点位置描述
     */
    private String toLocationDescription;

    /**
     * 分段依据
     */
    private String riskaCcroding;

    /**
     * 地区等级
     */
    private String areaLevel;

    /**
     * 风险评价方法
     */
    private String evaluateMethod;

    /**
     * 相对风险评分
     */
    private String relativeRiskScore;

    /**
     * 第三方破坏评分
     */
    private String damageScore;

    /**
     * 腐蚀评分
     */
    private String corrosionScore;

    /**
     * 设计与施工缺陷评分
     */
    private String desConstrScore;

    /**
     * 地质灾害评分
     */
    private String geohazardScore;

    /**
     * 误操作评分
     */
    private String operationScore;

    /**
     * 泄漏影响系数
     */
    private String leadCoefficient;

    /**
     * 风险等级
     */
    private String riskGrade;

    /**
     * 主要威胁因素
     */
    private String mainThreats;

    /**
     * 完整性评价建议
     */
    private String riskProposal;

    /**
     * 风险减缓建议措施
     */
    private String measure;

    /**
     * 风险是否已控制到可接受范围之内:0，可以接受，1，不可接受
     */
    private String isControllable;

    /**
     * 采取的风险控制措施
     */
    private String controlMeasures;

    /**
     * 实施时间（yyyyMMdd）
     */
    private String implementDate;

    /**
     * 风险评价时间（yyyyMMdd）
     */
    private String evaluateTime;

    /**
     * 风险评价单位
     */
    private String evaluateCompany;

    /**
     * 下次风险评价时间（yyyyMM）
     */
    private String nextEvaluateTime;

    /**
     * 记录人
     */
    private String recrder;

    /**
     * 记录时间
     */
    private String recordTime;

    /**
     * 起点绝对距离（m）
     */
    private String fromMileage;

    /**
     * 起点最近参考
     */
    private String fromReference;

    /**
     * 起点相对最近参考点距离
     */
    private String fromReferenceDistance;

    /**
     * 终点绝对距离（m）
     */
    private String toMileage;

    /**
     * 终点最近参考
     */
    private String toReference;

    /**
     * 终点相对最近参考点距离
     */
    private String toReferenceDistance;

    /**
     * 链接GIS结果表
     */
    private String gisId;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public String getPipeLineName() {
        return pipeLineName;
    }

    public void setPipeLineName(String pipeLineName) {
        this.pipeLineName = pipeLineName;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getCustomNumber() {
        return customNumber;
    }

    public void setCustomNumber(String customNumber) {
        this.customNumber = customNumber;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getLength() {
        return length;
    }

    public void setLength(String length) {
        this.length = length;
    }

    public String getFromLocationDescription() {
        return fromLocationDescription;
    }

    public void setFromLocationDescription(String fromLocationDescription) {
        this.fromLocationDescription = fromLocationDescription;
    }

    public String getToLocationDescription() {
        return toLocationDescription;
    }

    public void setToLocationDescription(String toLocationDescription) {
        this.toLocationDescription = toLocationDescription;
    }

    public String getRiskaCcroding() {
        return riskaCcroding;
    }

    public void setRiskaCcroding(String riskaCcroding) {
        this.riskaCcroding = riskaCcroding;
    }

    public String getAreaLevel() {
        return areaLevel;
    }

    public void setAreaLevel(String areaLevel) {
        this.areaLevel = areaLevel;
    }

    public String getEvaluateMethod() {
        return evaluateMethod;
    }

    public void setEvaluateMethod(String evaluateMethod) {
        this.evaluateMethod = evaluateMethod;
    }

    public String getRelativeRiskScore() {
        return relativeRiskScore;
    }

    public void setRelativeRiskScore(String relativeRiskScore) {
        this.relativeRiskScore = relativeRiskScore;
    }

    public String getDamageScore() {
        return damageScore;
    }

    public void setDamageScore(String damageScore) {
        this.damageScore = damageScore;
    }

    public String getCorrosionScore() {
        return corrosionScore;
    }

    public void setCorrosionScore(String corrosionScore) {
        this.corrosionScore = corrosionScore;
    }

    public String getDesConstrScore() {
        return desConstrScore;
    }

    public void setDesConstrScore(String desConstrScore) {
        this.desConstrScore = desConstrScore;
    }

    public String getGeohazardScore() {
        return geohazardScore;
    }

    public void setGeohazardScore(String geohazardScore) {
        this.geohazardScore = geohazardScore;
    }

    public String getOperationScore() {
        return operationScore;
    }

    public void setOperationScore(String operationScore) {
        this.operationScore = operationScore;
    }

    public String getLeadCoefficient() {
        return leadCoefficient;
    }

    public void setLeadCoefficient(String leadCoefficient) {
        this.leadCoefficient = leadCoefficient;
    }

    public String getRiskGrade() {
        return riskGrade;
    }

    public void setRiskGrade(String riskGrade) {
        this.riskGrade = riskGrade;
    }

    public String getMainThreats() {
        return mainThreats;
    }

    public void setMainThreats(String mainThreats) {
        this.mainThreats = mainThreats;
    }

    public String getRiskProposal() {
        return riskProposal;
    }

    public void setRiskProposal(String riskProposal) {
        this.riskProposal = riskProposal;
    }

    public String getMeasure() {
        return measure;
    }

    public void setMeasure(String measure) {
        this.measure = measure;
    }

    public String getIsControllable() {
        return isControllable;
    }

    public void setIsControllable(String isControllable) {
        this.isControllable = isControllable;
    }

    public String getControlMeasures() {
        return controlMeasures;
    }

    public void setControlMeasures(String controlMeasures) {
        this.controlMeasures = controlMeasures;
    }

    public String getImplementDate() {
        return implementDate;
    }

    public void setImplementDate(String implementDate) {
        this.implementDate = implementDate;
    }

    public String getEvaluateTime() {
        return evaluateTime;
    }

    public void setEvaluateTime(String evaluateTime) {
        this.evaluateTime = evaluateTime;
    }

    public String getEvaluateCompany() {
        return evaluateCompany;
    }

    public void setEvaluateCompany(String evaluateCompany) {
        this.evaluateCompany = evaluateCompany;
    }

    public String getNextEvaluateTime() {
        return nextEvaluateTime;
    }

    public void setNextEvaluateTime(String nextEvaluateTime) {
        this.nextEvaluateTime = nextEvaluateTime;
    }

    public String getRecrder() {
        return recrder;
    }

    public void setRecrder(String recrder) {
        this.recrder = recrder;
    }

    public String getRecordTime() {
        return recordTime;
    }

    public void setRecordTime(String recordTime) {
        this.recordTime = recordTime;
    }

    public String getFromMileage() {
        return fromMileage;
    }

    public void setFromMileage(String fromMileage) {
        this.fromMileage = fromMileage;
    }

    public String getFromReference() {
        return fromReference;
    }

    public void setFromReference(String fromReference) {
        this.fromReference = fromReference;
    }

    public String getFromReferenceDistance() {
        return fromReferenceDistance;
    }

    public void setFromReferenceDistance(String fromReferenceDistance) {
        this.fromReferenceDistance = fromReferenceDistance;
    }

    public String getToMileage() {
        return toMileage;
    }

    public void setToMileage(String toMileage) {
        this.toMileage = toMileage;
    }

    public String getToReference() {
        return toReference;
    }

    public void setToReference(String toReference) {
        this.toReference = toReference;
    }

    public String getToReferenceDistance() {
        return toReferenceDistance;
    }

    public void setToReferenceDistance(String toReferenceDistance) {
        this.toReferenceDistance = toReferenceDistance;
    }

    public String getGisId() {
        return gisId;
    }

    public void setGisId(String gisId) {
        this.gisId = gisId;
    }

    public void forDomain(RiskAssessment domain) {

        // 主键
        this.id = domain.getId();
        // 创建备注
        this.remark = domain.getCreateRemark();
        // 管道ID
        this.pipeLineName = PipeLineUtil.getPipeLineName(domain.getPipeLineId());
        // 统一编号
        this.code = domain.getCode();
        // 风险段编号(自定义编号)
        this.customNumber = domain.getCustomNumber();
        // 风险段名称
        this.name = domain.getName();
        // 风险管段长度（m）
        this.length = NumberFormat.format(domain.getLength(), NumberFormat.FMT_PLACES3);
        //  起点位置描述
        this.fromLocationDescription = domain.getFromLocationDescription();
        // 终点位置描述
        this.toLocationDescription = domain.getToLocationDescription();
        // 分段依据
        this.riskaCcroding = CodeUtil.getName(domain.getRiskaCcroding());
        // 地区等级
        this.areaLevel = CodeUtil.getName(domain.getAreaLevel());
        // 风险评价方法
        this.evaluateMethod = CodeUtil.getName(domain.getEvaluateMethod());
        // 相对风险评分
        this.relativeRiskScore = NumberFormat.format(domain.getRelativeRiskScore());
        // 第三方破坏评分
        this.damageScore = NumberFormat.format(domain.getDamageScore());
        // 腐蚀评分
        this.corrosionScore = NumberFormat.format(domain.getCorrosionScore());
        // 设计与施工缺陷评分
        this.desConstrScore = NumberFormat.format(domain.getDesConstrScore());
        // 地质灾害评分
        this.geohazardScore = NumberFormat.format(domain.getGeohazardScore());
        // 误操作评分
        this.operationScore = NumberFormat.format(domain.getOperationScore());
        // 泄漏影响系数
        this.leadCoefficient = NumberFormat.format(domain.getLeadCoefficient());
        // 风险等级
        this.riskGrade = CodeUtil.getName(domain.getRiskGrade());
        // 主要威胁因素
        this.mainThreats = CodeUtil.getName(domain.getMainThreats());
        // 完整性评价建议
        this.riskProposal = CodeUtil.getName(domain.getRiskProposal());
        // 风险减缓建议措施
        this.measure = CodeUtil.getNames(StringUtils.isNullEmpty(domain.getMeasure()) ? null : domain.getMeasure().split(","));
        // 风险是否已控制到可接受范围之内:0，可以接受，1，不可接受
        this.isControllable = domain.getIsControllable()==0 ? "是" : "否";
        // 采取的风险控制措施
        this.controlMeasures = CodeUtil.getNames(StringUtils.isNullEmpty(domain.getControlMeasures()) ? null : domain.getControlMeasures().split(","));
        // 实施时间（yyyyMMdd）
        this.implementDate = StringUtils.convertDateToString(domain.getImplementDate(), StringUtils.DATE);
        // 风险评价时间（yyyyMMdd）
        this.evaluateTime = StringUtils.convertDateToString(domain.getEvaluateTime(), StringUtils.DATE);
        // 风险评价单位
        this.evaluateCompany = domain.getEvaluateCompany();
        // 下次风险评价时间（yyyyMM）
        this.nextEvaluateTime = DateFormat.format(domain.getNextEvaluateTime());
        // 记录人
        this.recrder = domain.getRecrder();
        // 记录时间
        this.recordTime = DateFormat.format(domain.getRecordTime());
        // 起点绝对距离（m）
        this.fromMileage = NumberFormat.format(domain.getFromMileage(), NumberFormat.FMT_PLACES3);
        // 起点最近参考
        this.fromReference = domain.getFromReference();
        // 起点相对最近参考点距离
        this.fromReferenceDistance = NumberFormat.format(domain.getFromReferenceDistance(), NumberFormat.FMT_PLACES3);
        // 终点绝对距离（m）
        this.toMileage = NumberFormat.format(domain.getToMileage(), NumberFormat.FMT_PLACES3);
        // 终点最近参考
        this.toReference = domain.getToReference();
        // 终点相对最近参考点距离
        this.toReferenceDistance = NumberFormat.format(domain.getToReferenceDistance(), NumberFormat.FMT_PLACES3);
        // 链接GIS结果表
        this.gisId = domain.getGisId();
    }

    public Page<RiskAssessmentVO> forDomain(Page<RiskAssessment> riskAssessmentList) {
        Page<RiskAssessmentVO> pageList = new Page<RiskAssessmentVO>();
        for (RiskAssessment riskAssessment : riskAssessmentList) {
            RiskAssessmentVO riskAssessmentVO = new RiskAssessmentVO();
            riskAssessmentVO.forDomain(riskAssessment);
            pageList.add(riskAssessmentVO);
        }
        BaseVOUtil.converterPage(riskAssessmentList, pageList);
        return pageList;
    }
}
